#!/bin/sh

# Use neovim for vim if present.
[ -x "$(command -v nvim)" ] && alias vim="nvim" vimdiff="nvim -d"

# Verbosity and settings that you pretty much just always are going to want.
# My Preferences
alias \
	YT="straw-viewer" \
	ytg="gtk-straw-viewer" \
	fonts_refresh="fc-cache -f -v" \
	lsa="exa -alFgh --group-directories-first" \
	p="sudo pacman -S" \
	r="sudo pacman -R" \
	u="sudo pacman -U" \
	syu="sudo pacman -Syu" \
	ss="sudo pacman -Ss" \
	pz="pacman -Qi | awk '/^Name/{name=\$3} /^Installed Size/{print \$4\$5, name}' | sort -h" \
	vimwiki="nvim ~/tent/hogsmead/Softwares/home/vimwiki/index.md" \
	vr='~/.config/vifm/scripts/vifmrun'
	#doas="doas --"


alias \
	cp="cp -iv" \
	mv="mv -iv" \
	rm="rm -vI" \
	mkd="mkdir -pv" \
	yt="youtube-dl --add-metadata -i" \
	yta="yt -x -f bestaudio/best" \
	ffmpeg="ffmpeg -hide_banner"

# Colorize commands when possible.
alias \
	ls="ls -hN --color=auto --group-directories-first" \
	grep="grep --color=auto" \
	diff="diff --color=auto" \
	ccat="highlight --out-format=ansi"

# These common commands are just too long! Abbreviate them.
alias \
	ka="killall" \
	g="git" \
	trem="transmission-remote" \
	sdn="sudo shutdown -h now" \
	f="$FILE" \
	e="$EDITOR" \
	v="$EDITOR" \
	xi="sudo xbps-install" \
	xr="sudo xbps-remove -R" \
	xq="xbps-query" \
	z="zathura"

alias \
	magit="nvim -c MagitOnly" \
	ref="shortcuts >/dev/null; source ${XDG_CONFIG_HOME:-$HOME/.config}/shortcutrc ; source ${XDG_CONFIG_HOME:-$HOME/.config}/zshnameddirrc" \
	weath="less -S ${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport" \
	tmux="tmux -f ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"

### ARCHIVE EXTRACTION
# usage: ex <file>
ex ()
{
  if [ -f $1 ] ; then
    case $1 in
      *.tar.bz2)   tar xjf $1   ;;
      *.tar.gz)    tar xzf $1   ;;
      *.bz2)       bunzip2 $1   ;;
      *.rar)       unrar x $1   ;;
      *.gz)        gunzip $1    ;;
      *.tar)       tar xf $1    ;;
      *.tbz2)      tar xjf $1   ;;
      *.tgz)       tar xzf $1   ;;
      *.zip)       unzip $1     ;;
      *.Z)         uncompress $1;;
      *.7z)        7z x $1      ;;
      *.deb)       ar x $1      ;;
      *.tar.xz)    tar xf $1    ;;
      *.tar.zst)   unzstd $1    ;;
      *)           echo "'$1' cannot be extracted via ex()" ;;
    esac
  else
    echo "'$1' is not a valid file"
  fi
}

# root privileges
alias doas="doas --"

# navigation
alias \
	..='cd ..' \
	...='cd ../..' \
	.3='cd ../../..' \
	.4='cd ../../..' \
	.5='cd ../../../..' \
	.6='cd ../../../../..'

# pacman and yay
alias syyu='sudo pacman -Syyu'                 # update only standard pkgs
alias yu="yay -Sua --noconfirm"              # update only AUR pkgs
alias ysyu="yay -Syu --noconfirm"              # update standard pkgs and AUR pkgs
alias unlock="sudo rm /var/lib/pacman/db.lck"    # remove pacman lock
alias cleanup='sudo pacman -Rns $(pacman -Qtdq)' # remove orphaned packages

## get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'

## get top process eating cpu ##
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'

# git
alias \
	addup='git add -u' \
	addall='git add .' \
	branch='git branch' \
	checkout='git checkout' \
	commit='git commit -m' \
	fetch='git fetch' \
	pull='git pull' \
	push='git push' \
	status='git status' \
	tag='git tag' \
	newtag='git tag -a'

# the terminal rickroll
alias rr='curl -s -L https://raw.githubusercontent.com/keroserene/rickrollrc/master/roll.sh | bash'


# switch between shells
alias \
	tobash="sudo chsh $USER -s /bin/bash && echo 'Now log out.'" \
	tozsh="sudo chsh $USER -s /bin/zsh && echo 'Now log out.'" \
	tofish="sudo chsh $USER -s /bin/fish && echo 'Now log out.'"

# youtube-dl
alias \
	yta-aac="youtube-dl --extract-audio --audio-format aac " \
	yta-best="youtube-dl --extract-audio --audio-format best " \
	yta-flac="youtube-dl --extract-audio --audio-format flac " \
	yta-m4a="youtube-dl --extract-audio --audio-format m4a " \
	yta-mp3="youtube-dl --extract-audio --audio-format mp3 " \
	yta-opus="youtube-dl --extract-audio --audio-format opus " \
	yta-vorbis="youtube-dl --extract-audio --audio-format vorbis " \
	yta-wav="youtube-dl --extract-audio --audio-format wav " \
	ytv-best="youtube-dl -f bestvideo+bestaudio "
